package cn.tedu.smartos.volunteer.controller;

import cn.tedu.smartos.activity.pojo.vo.ActivityVO;
import cn.tedu.smartos.base.response.JsonResult;
import cn.tedu.smartos.baseuser.pojo.vo.UserVO;
import cn.tedu.smartos.volunteer.Service.VolunteerService;
import cn.tedu.smartos.volunteer.pojo.dto.ActivityQueryParam;
import cn.tedu.smartos.volunteer.pojo.dto.PasswordUpdateParam;
import cn.tedu.smartos.volunteer.pojo.dto.PointsExchangeRequest;
import cn.tedu.smartos.volunteer.pojo.dto.UserUpdateParam;
import cn.tedu.smartos.volunteer.pojo.entity.PointsExchange;
import cn.tedu.smartos.volunteer.pojo.entity.PointsGoods;
import cn.tedu.smartos.volunteer.pojo.vo.VolunteerInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "志愿者管理模块")
@Slf4j
@RequestMapping("/api/volunteer")
public class VolunteerController {

    @Autowired
    private VolunteerService volunteerService;

    @GetMapping("/userInfo")
    @ApiOperation("获取个人信息")
    public JsonResult getUserInfo(@RequestParam String username) {
        log.debug("开始处理【获取个人信息】的请求,参数:{}", username);
        UserVO userVO = volunteerService.getUserInfo(username);
        return JsonResult.ok(userVO);
    }

    @PostMapping("/updateUserInfo")
    @ApiOperation("修改个人信息")
    public JsonResult updateUserInfo(@RequestBody UserUpdateParam param) {
        return volunteerService.updateUserInfo(param);
    }

    @PostMapping("/updatePassword")
    @ApiOperation("修改密码")
    public JsonResult updatePassword(@RequestBody PasswordUpdateParam param) {
        return volunteerService.updatePassword(param);
    }

    @GetMapping("/volunteerInfo")
    @ApiOperation("获取志愿者信息")
    public JsonResult getVolunteerInfo(@RequestParam String username) {
        log.debug("开始处理【获取志愿者信息】的请求,参数:{}", username);
        VolunteerInfoVO volunteerInfo = volunteerService.getVolunteerInfo(username);
        return JsonResult.ok(volunteerInfo);
    }


    @GetMapping("/pointsGoods")
    @ApiOperation("获取积分商品列表")
    public JsonResult getAllPointsGoods() {
        List<PointsGoods> goodsList = volunteerService.getAllPointsGoods();
        return JsonResult.ok(goodsList);
    }


    @ApiOperation("兑换积分商品")
    @PostMapping("/exchangePointsGoods")
    public JsonResult exchangePointsGoods(@RequestBody PointsExchangeRequest request) {
        return volunteerService.exchangePointsGoods(
                request.getUsername(),
                request.getGoodsId(),
                request.getQuantity()
        );
    }

    @GetMapping("/myPointsExchanges")
    @ApiOperation("获取我的积分兑换列表")
    public JsonResult getMyPointsExchanges(@RequestParam String username) {
        List<PointsExchange> exchanges = volunteerService.getMyPointsExchanges(username);
        return JsonResult.ok(exchanges);
    }
}